﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RPGXEngine
{
    public class VarVariableType : IVariableType
    {
        #region IVariableType Members

        public DataType Type
        {
            get { return DataType.Var; }
        }

        public string Name
        {
            get { return this._name; }
        }
        private string _name = String.Empty;

        public int SizeInBytes
        {
            get { return 0; }
        }

        public Dictionary<string, IVariableType> MetaData
        {
            get { return this._metaData; }
        }
        private Dictionary<string, IVariableType> _metaData = new Dictionary<string, IVariableType>();

        public object Value
        {
            get { return _value; }
            set { _value = value; }
        }
        private object _value = null;

        #endregion

        #region Public Methods

        public VarVariableType(string name)
        {
            this._name = name;
        }

        public void SetValue(object value)
        {
            this._value = value;
        }

        public void SetValue(IVariableType value)
        {
            this._value = value.Value;

            foreach (var key in value.MetaData.Keys)
            {
                if (!this.MetaData.ContainsKey(key))
                    this.MetaData.Add(key, null);

                this.MetaData[key] = value.MetaData[key];
            }
        }

        public void AddValue(object value)
        {
            TypeManager tm = new TypeManager();
            this._value = tm.AddValues(this._value, value);
        }

        public void AddValue(IVariableType value)
        {
            TypeManager tm = new TypeManager();
            this._value = tm.AddValues(this._value, value.Value);
        }

        public void MinusValue(object value)
        {
            TypeManager tm = new TypeManager();
            this._value = tm.MinusValues(this._value, value);
        }

        public void MinusValue(IVariableType value)
        {
            TypeManager tm = new TypeManager();
            this._value = tm.MinusValues(this._value, value.Value);
        }

        public void MultiplyValue(object value)
        {
            TypeManager tm = new TypeManager();
            this._value = tm.MultiplyValues(this._value, value);
        }

        public void MultiplyValue(IVariableType value)
        {
            TypeManager tm = new TypeManager();
            this._value = tm.MultiplyValues(this._value, value.Value);
        }

        public void DivideValue(object value)
        {
            TypeManager tm = new TypeManager();
            this._value = tm.DivideValues(this._value, value);
        }

        public void DivideValue(IVariableType value)
        {
            TypeManager tm = new TypeManager();
            this._value = tm.DivideValues(this._value, value.Value);
        }

        #endregion
    }
}
